home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / shadobox.arc / WDEF.H < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-19  |  13.8 KB  |  321 lines

  1. /* "WDEF.H       ver 0.0          11/24/87"   SHADOW BOXES
  2.    Copyright (c) 1987 John G. Donohue
  3. 09/19/87 jgd 0.0a Replaced macro scn_edge() by fn.
  4. 09/25/87 09/26/87 jgd 0.1 Change attributes from 0 to allow scn_was().
  5.         Eliminate _rectangle and _screen struct names by typedef earlier.
  6.         Add defines, etc.
  7. 11/23/87 jgd 0.2 Added LEFT, RIGHT, etc.
  8. 11/24/87 jgd 0.3 Separated non-portables from portables.  Cleaned up LINT stuff.
  9.         
  10.         Check (change?) CANCEL define to -20???
  11. */
  12. /*****************************************************************************/
  13. /* The first part of this file contains the items you must change if you
  14.    change CPUs, compilers, or screen implementations.  The second part
  15.    contains standard, if arbitrary, definitions.  Leave those alone. */
  16. /*****************************************************************************/
  17.  
  18. /*****************************************************************************/
  19. /* Switches for conditional compiling. */
  20. #define TESTING 1       /* Print the various testing messages. */
  21. #define LINT    1       /* Prototyping is allowed in this compiler. */
  22.  
  23. /*****************************************************************************/
  24. /* If your screen is memory-mapped (can be read) define this.
  25.    If you output to it as a terminal, DON'T define it.
  26.    This affects cursor positioning and reading/writing rectangles.
  27.    Not fully implemented if not defined. */
  28. #define MEMMAPPED 1
  29. #define STDWID  80
  30. #define STDHGT  25
  31.  
  32. /*****************************************************************************/
  33. /* Data types.  All these must be defined. */
  34. #define TF              int     /* A Boolean value, 1 or 0 */
  35. #define ERRCODE         int     /* >=16 bits, signed, integer-related */
  36. #define COORD           int     /* >=16 bits, signed, no shorter than int */
  37. #define WNUM            int     /* >=16 bits, signed, no shorter than int */
  38. #define BITS            unsigned int    /* unsigned, at least as large as
  39.                                    a character and all its attribute bits */
  40. #define SCNCHAR         unsigned int    /* unsigned, at least as large as
  41.                                    a character and all its attribute bits */
  42. #define KEYCHAR         int     /* a key value (function keys, etc., are
  43.                                    converted to value|0xFE00), possibly
  44.                                    converted by getcv() to a logical
  45.                                    meaning such as SAVE, LEFT, etc., which
  46.                                    is of the form 0xFFxx.
  47.                                    >=16 bits, signed, no shorter than int */
  48.  
  49. /*****************************************************************************/
  50. /* Attributes of characters to be displayed on screen.
  51.    Each must be defined as bit positions, which may be ORed with other bits, 
  52.    including background and foreground colors, to make an attribute (WATTR),
  53.    which is a logical value, and perhaps not equivalent to the way 
  54.    the hardware expects an attribute.
  55.    A SCNCHAR is an int-format (BITS, actually) version of a character and its
  56.    attribute (possibly transformed to physical hardware requirements),
  57.    shoved together into a single representation.  A rectangular array of 
  58.    SCNCHARS forms the buffer in which a window's image is saved.
  59.    The function
  60.         SCNCHAR ca_to_scnchar(int c, WATTR a);
  61.    combines the character and attribute, transforming the attribute to
  62.    physical needs if necessary, into a single SCNCHAR data type.
  63.    Although the IBM-PC implementation here uses a WATTR bit configuration
  64.    which matches the physical bit requirement, that would not necessarily
  65.    always be the case.  In fact, you could leave all the color and BLINK
  66.    definitions as they are, and just change this function (along with those
  67.    that read just attributes), to change to a different environment. */
  68.  
  69. #define WATTR           BITS    /* This MUST be defined this way. */
  70.  
  71. /* Define the bit positions.  Regardless of physical requirements in a
  72.    SCNCHAR, the logical requirement in a WATTR is that a 1 bit means
  73.    "do it", and a 0 bit means "don't do it".  The logical values have been
  74.    chosen here to match the IBM PC's physical values, making the function
  75.         SCNCHAR ca_to_scnchar(int c, WATTR a);
  76.    trivial to implement. */
  77. #define BRIGHT          (WATTR) 0x08
  78. #define BLINK           (WATTR) 0x80
  79. #define BG_BITS         (WATTR) 0x70
  80. #define FG_BITS         (WATTR) 0x07
  81.  
  82. /* Foreground colors, in their WATTR bit positions */
  83. #define FG_BLACK        (WATTR) 0x00
  84. #define FG_BLUE         (WATTR) 0x01
  85. #define FG_GREEN        (WATTR) 0x02
  86. #define FG_CYAN         (WATTR) 0x03
  87. #define FG_RED          (WATTR) 0x04
  88. #define FG_MAGENTA      (WATTR) 0x05
  89. #define FG_BROWN        (WATTR) 0x06
  90. #define FG_WHITE        (WATTR) 0x07
  91.  
  92. /* Background colors, in their WATTR bit positions */
  93. #define BG_BLACK        (WATTR) 0x00
  94. #define BG_BLUE         (WATTR) 0x10
  95. #define BG_GREEN        (WATTR) 0x20
  96. #define BG_CYAN         (WATTR) 0x30
  97. #define BG_RED          (WATTR) 0x40
  98. #define BG_MAGENTA      (WATTR) 0x50
  99. #define BG_BROWN        (WATTR) 0x60
  100. #define BG_WHITE        (WATTR) 0x70
  101.  
  102. #define STDATTR         (WATTR) (FG_WHITE | BG_BLACK )  /* normal screen */
  103. #define REVERSEVIDEO    (WATTR) (FG_BLACK | BG_WHITE )
  104. #define shadowed(sc)    (sc & ~( (BG_BITS|BRIGHT) << 8 ))
  105.                                 /* How to put a SCNCHAR in shadow.
  106.                                    Note that this MUST correspond with 
  107.                                    the ca_to_scnchar() function. */
  108. #define TRANSPARENT     (FG_WHITE | BG_WHITE | BLINK)   /* which you would
  109.                                   never use for any other purpose.
  110.                                   NOTE: Yes, a PC with a monochrome card
  111.                                   would display this as white on black, but
  112.                                   we use it for internal purposes, and it
  113.                                   never physically reaches the PC screen. */
  114.  
  115. /*****************************************************************************/
  116. /* Everything below here is standard. */
  117. /*****************************************************************************/
  118.  
  119. #define HELP            -18
  120. /* #define CANCEL          -20 */
  121. #define CANCEL          ESC
  122. #define UP              -21             /* Also direction of window scroll */
  123. #define DOWN            -22
  124. #define LEFT            -23
  125. #define RIGHT           -24
  126. #define PGUP            -25
  127. #define PGDOWN          -26
  128.  
  129. #define POSITION        (COORD) -99
  130.         /* must be neither a valid coordinate, NOR -1 nor -2 */
  131.  
  132. #define STDWNUM 0       /* the standard window before you open any windows */
  133. #define MAXWIN  30      /* maximum number of windows */
  134.  
  135. /*****************************************************************************/
  136. /* Attribute types, for use in the w_setattr(int type, WATTR a) function.
  137.    Must not use 0, since these may be imbedded in text strings to change
  138.    attributes in mid-string.  (See w_puts().) */
  139. #define SET_    1
  140. #define RESET_  2
  141. #define FGC_    3
  142. #define BGC_    4
  143. #define ENTIRE_ 5
  144.  
  145. /*****************************************************************************/
  146. /* In window structure, these are bits which make up .wstatus.
  147.    Several are defined by w_def(), others occur later.  
  148.    Not all are implemented. */
  149.  
  150.   /* defined by w_def */
  151. #define WNORMAL_        (BITS) 0
  152. #define CLEAR_ON_OPEN   (BITS) 1       /* EVERY time it is opened (redisplayed) */
  153. #define NOSAVE_ON_CLOSE (BITS) 2       /* prevents buffer allocation for .wsave */
  154. #define DELETE_ON_CLOSE (BITS) 4
  155. /* #define DONT_ERASE      (BITS) 8  */
  156. /* #define DONT_CLOSE      (BITS) 16 */   /* envisioned for STDWNUM only! */
  157. #define NO_SCROLL       (BITS) 64
  158. #define INVISIBLE       (BITS) 128
  159.   /* states */
  160. #define WDEFINED_       256
  161. #define WOPENED_        512
  162. #define WMAYDELETE_     (BITS) 1024
  163.         /* system sets this if w_delete() requested but not yet possible. */
  164.  
  165. /*****************************************************************************/
  166. /* Borders.  The actual character arrays used are in WBORD.I, which is
  167.    included into WINDOW.C.  These bit masks show which bits are used
  168.    for values of bordstyle.
  169.    The 8 bits of LEFT, RIGHT, TOP, BOTTOM must be the lowest 8, as they
  170.    are used as indexes into an array.  0=no border. 
  171.    SHADOW and EDGE are in ADDITION to other borders.
  172.    SHADOW requires decrementing left, incrementing wid, incrementing hgt. */
  173. #define BORD_EDGE       (BITS) 0x0200
  174. #define BORD_SHADOW     (BITS) 0x0100
  175. /* For these next four, in each two-bit pair, the values represent:
  176.      0 = no border, 1 = single line, 2 = double line, 3 = block.
  177.    The SHIFT macros represent the number of bits to shift that pair right
  178.    to put it in the range 0 to 3.
  179.    The "bordstyle" is
  180.        +---+---+---+---+---+---+---+---+---+---+
  181.        |edg|shd|  top  | bottom|  left | right |
  182.        +---+---+---+---+---+---+---+---+---+---+
  183. */
  184. #define BORD_TOP        (BITS) 0x00c0
  185. #define BORD_BOTTOM     (BITS) 0x0030
  186. #define BORD_LEFT       (BITS) 0x000c
  187. #define BORD_RIGHT      (BITS) 0x0003
  188. #define BORD_TSHIFT     6
  189. #define BORD_BSHIFT     4
  190. #define BORD_LSHIFT     2
  191. #define BORD_RSHIFT     0
  192. #define BORD_MASK       3       /* Rightmost 2 bits get masked after shift. */
  193. /* These are subscripts into the array of border characters. */
  194. #define BORD_L  0
  195. #define BORD_R  1
  196. #define BORD_T  2
  197. #define BORD_B  3
  198. #define BORD_TL 4
  199. #define BORD_TR 5
  200. #define BORD_BL 6
  201. #define BORD_BR 7
  202.  
  203. /*****************************************************************************/
  204. /***  STRUCTURES  ***/
  205. /*****************************************************************************/
  206.  
  207. typedef struct
  208. {
  209.         COORD  rhgt, rwid, rtop, rleft;
  210. } RECT;
  211.  
  212. /*****************************************************************************/
  213. typedef struct
  214. {
  215.         int    sbase;           /* set to B000H or B800H by w_init () */
  216. /* same as        int    vidseg; */
  217.         COORD  shgt, swid;
  218. } SCN;
  219.  
  220. /*****************************************************************************/
  221. struct _window
  222. {
  223.   /* When defined */
  224.         BITS    wstatus;        /* initially zero if no window defined here. */
  225.         BITS    wbordstyle;
  226.         WATTR   wbordattr;
  227.         RECT    wpane;          /* "writeable" area of window.  May be adjusted
  228.                                    after open by "pane_" functions. */
  229.         RECT    wrectb;         /* possibly bigger than above for borders,
  230.                                    shadow. */
  231.   /* When opened */
  232.         int     wscreen;        /* screen page.  Not necessarily hardware-
  233.                                    related.  Currently force screen 0. */
  234.         SCNCHAR *wunder;        /* pointer to 1st char of block where stuff
  235.                                    covered up is saved. */
  236.   /* When closed */
  237.         WATTR   wdftattr;       /* default attribute in this window (scroll) */
  238.         WATTR   wattr;          /* last set attribute in this window */
  239.         COORD   wrow, wcolumn;  /* 0,0 when w_def()'d, saved cursor value 
  240.                                    when closed. */
  241.         SCNCHAR *wsave;         /* window data, incl border, written to ONLY
  242.                                    when window closed (unless wstatus has
  243.                                    NOSAVE).
  244.                                    IF you later allow writing to memory images
  245.                                    as well as those on screen, or to "hidden"
  246.                                    windows, this may be written to on each
  247.                                    character. */
  248. };
  249.  
  250. /*****************************************************************************/
  251. struct  REGS
  252. {
  253.         char al,ah,bl,bh,cl,ch,dl,dh,others[6];
  254. };
  255. /*****************************************************************************/
  256. #ifdef LINT
  257. ERRCODE w_init(void);
  258. WNUM    w_def(WNUM, BITS, COORD, COORD, WATTR, BITS, WATTR);
  259. ERRCODE w_open(WNUM, COORD, COORD);
  260. ERRCODE w_current(WNUM);
  261. ERRCODE w_close(WNUM);
  262. ERRCODE w_delete(WNUM);
  263. ERRCODE w_puts(char *);
  264. int     w_putc(int);
  265. ERRCODE w_setattr(int, WATTR);
  266. ERRCODE w_cursor(COORD, COORD);
  267. ERRCODE w_scroll(int, int);
  268. ERRCODE w_err(ERRCODE);
  269. ERRCODE scn_ws(char *);
  270. ERRCODE scn_was(char *);
  271. ERRCODE scn_cursor(COORD, COORD);
  272. ERRCODE scn_saverect(RECT *, SCNCHAR *);
  273. ERRCODE scn_loadrect(RECT *, SCNCHAR *);
  274. ERRCODE scn_edge(WATTR attr);
  275.  
  276. int     scn_wc(int c);
  277. SCNCHAR scn_wscnchar(SCNCHAR);
  278. SCNCHAR scn_rscnchar(void);
  279. /* Not presently used
  280. WATTR   scn_ra(void);
  281. int     scn_wconly(int c);
  282. WATTR   scn_waonly(WATTR);
  283. */
  284. SCNCHAR ca_to_scnchar(int, WATTR);
  285. ERRCODE hw_initscn(void);
  286. ERRCODE hw_cursor(void);
  287.  
  288. KEYCHAR getv(void);
  289. KEYCHAR getcv(void);
  290.  
  291.         /* Functions from the Standard Library */
  292.  
  293. char    *calloc(unsigned int, unsigned int);
  294. void    exit(int);
  295. void    free(char *);
  296. int     printf(char *, ...);
  297.  
  298.         /* Functions that are MS-DOS- (and possibly compiler-) dependent */
  299.  
  300. int             int86(int, struct REGS *, struct REGS *);
  301. unsigned int    peek(unsigned int, unsigned int); 
  302.         /* CAUTION: DIFFERENT COMPILERS DO peek() DIFFERENTLY */
  303. #endif
  304.  
  305. #ifdef MEMMAPPED
  306. #define hw_setattr() /* Don't send anything to screen when attribute changes. */
  307. #else
  308. #ifdef LINT
  309. ERRCODE hw_setattr(void);
  310. #endif
  311. #endif
  312.  
  313. #define w_writerc(row, col, s)  (w_cursor(row, col) ? werrnum : w_puts(s))
  314. #define iswopen(w)              (windows[w].wstatus & WOPENED_)
  315. #define BUG(msg)                printf(msg);
  316. #define w_getcy()               cw->wrow
  317. #define blink()                 w_setattr(SET_, BLINK)
  318. #define noblink()               w_setattr(RESET_, BLINK)
  319. #define bright()                w_setattr(SET_, BRIGHT)
  320. #define nobright()              w_setattr(RESET_, BRIGHT)
  321.